<template>
    <div class="menu_list">
        <div class="icon_wrap" v-for="item in windowList" :key="item.id" :class="item.isOpen ? 'active' : ''"
            @click="openOrCloseWindow(item)">
            <n-icon :size="22">
                <component :is="item.icon"></component>
            </n-icon>
        </div>
    </div>
</template>

<script setup lang="ts" name="HomeMenu">
import { useAppStore, WindowItem } from '@/stores/app';
import { storeToRefs } from 'pinia';
import BoardChannel from '@/utils/boardChannel';
// 前端
import { listen } from '@tauri-apps/api/event';

listen('window-hidden', (event:any) => {
    appStore.clearWindow(event.payload.windowLabel);
});
const channel = new BoardChannel('bp-system');
const appStore = useAppStore();
const { windowList } = storeToRefs(appStore);
const openOrCloseWindow = async (row: WindowItem) => {
    appStore.changeWindowState(row.id);
}
channel.on('hideWindow', (windowLabel) => {
    appStore.clearWindow(windowLabel);
})
</script>

<style lang="scss" scoped>
.menu_list {
    display: flex;
    width: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1em;

    .icon_wrap {
        width: 50px;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        border-radius: 6px;
        transition: .37s all;

        &:hover {
            @include useTheme {
                background: getVar('navBg');
            }
        }

        &.active {
            @include useTheme {
                background: getVar('navBg');
            }

            i {
                color: #4090EF;
            }
        }

        i {
            color: #fff;
        }
    }
}
</style>